﻿Public Class perCadContato
    Inherits perPadrao
#Region "Variáveis"
    Private objBuscaId As New perProximoId
#End Region

#Region "Métodos"
    Public Sub AlterarContatoAgendado(ByVal iIDContatoAgendado As Int32, ByVal iIDCliente As Int32, ByVal iIDContato As Int32, ByVal dtDiaContato As Date, _
                                            ByVal sHoraContato As String, ByVal sObservacoes As String)

        Dim sSql As String

        Try
            sSql = "UPDATE DC_AgendaLigacoes SET " & vbCrLf
            sSql &= "IDCliente = " & iIDCliente & "," & vbCrLf
            sSql &= "IDContato = " & iIDContato & "," & vbCrLf
            sSql &= "Data = '" & dtDiaContato & "'," & vbCrLf
            sSql &= "Hora = '" & sHoraContato & "'," & vbCrLf
            sSql &= "Observacoes = '" & sObservacoes & "'," & vbCrLf
            sSql &= "WHERE IdContAgendado = " & iIDContatoAgendado

            MyBase.executarAcao(sSql)

        Catch ex As Exception
            Throw New Exception("Ocorreu uma exceção no método 'InserirContatoAgendado'" & Environment.NewLine & Environment.NewLine & ex.Message)
        End Try

    End Sub
    Public Function InserirContatoAgendado(ByVal iIDCliente As Int32, ByVal iIDContato As Int32, ByVal dtDiaContato As Date, _
                                            ByVal sHoraContato As String, ByVal sObservacoes As String, ByVal iIDUsuario As Int32) As Int32

        Dim sSql As String
        Dim iIDContAgendado As Long

        Try
            iIDContAgendado = objBuscaId.BuscaID("IdContAgendado", "DC_AgendaLigacoes")

            sSql = "INSERT INTO DC_AgendaLigacoes "
            sSql &= "(IDContAgendado,"
            sSql &= "IDCliente,"
            sSql &= "IDContato,"
            sSql &= "Data,"
            sSql &= "Hora,"
            sSql &= "Observacoes,"
            sSql &= "IDUsuario"
            sSql &= ")"
            sSql &= "VALUES"
            sSql &= "(" & iIDContAgendado & "," & vbCrLf
            sSql &= iIDCliente & ","
            sSql &= iIDContato & ","
            sSql &= "'" & dtDiaContato & "',"
            sSql &= "'" & sHoraContato & "',"
            sSql &= "'" & sObservacoes & "',"
            sSql &= iIDUsuario
            sSql &= ")"

            MyBase.executarAcao(sSql)
            Return iIDContAgendado

        Catch ex As Exception
            Return 0
            Throw New Exception("Ocorreu uma exceção no método 'InserirContatoAgendado'" & Environment.NewLine & Environment.NewLine & ex.Message)

        End Try


    End Function
    Public Function NumeroContatosDia(ByVal dtDiaContato As Date) As Int32
        Dim sSql As String
        Dim dtResultado As New DataSet


        Try
            sSql = "SELECT COUNT(ProximoContato) as NContatos" & vbCrLf
            sSql &= "  FROM DC_Clientes" & vbCrLf
            sSql &= " WHERE DC_Clientes.ProximoContato = @Data"

            With MyBase.SQLCmd.Parameters
                .Clear()
                .AddWithValue("@Data", dtDiaContato.Date)
            End With

            dtResultado = MyBase.executarConsulta(sSql, "DC_Clientes")

            If (dtResultado.Tables("DC_Clientes").Rows.Count > 0) Then
                Return dtResultado.Tables("DC_Clientes").Rows(0).Item("NContatos")
            Else
                Return 0
            End If

        Catch ex As Exception

            Throw New Exception("Exceção no método 'NumeroContatosDia'." & Environment.NewLine & Environment.NewLine & ex.Message)

        End Try

    End Function
#End Region
End Class
